package com.ericssonlabs;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.qrcodeandpay.R;
import com.zxing.activity.CaptureActivity;

/**
 * @author Administrator
 * 
 */
public class MainAcitivty extends Activity implements OnClickListener {

	private Button scanQRCode, createQRCode, payZFB, payWeChat, payUnionpay;
	private TextView scanQRCodeRes;
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		findViewById(R.id.scanQRCode).setOnClickListener(this);
		findViewById(R.id.createQRCpde).setOnClickListener(this);
		findViewById(R.id.payZFB).setOnClickListener(this);
		findViewById(R.id.payWeChat).setOnClickListener(this);
		findViewById(R.id.payUnionpay).setOnClickListener(this);
		scanQRCodeRes = (TextView) findViewById(R.id.scanQRCodeRes);
		
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		//扫描二维码
		case R.id.scanQRCode:
			Intent openCameraIntent = new Intent(MainAcitivty.this,
					CaptureActivity.class);
			startActivityForResult(openCameraIntent, 0x11);
			break;
	    //生成二维码
		case R.id.createQRCpde:
			Intent intent=new Intent(MainAcitivty.this,CreateQRCode.class);
			startActivity(intent);
			break;
		//银联支付
		case R.id.payUnionpay:

			break;
		//支付宝支付
		case R.id.payZFB:

			break;
		//微信支付
		case R.id.payWeChat:

			break;
		default:
			break;
		}
	}
	
	/*
	 * 展示扫描的二维码结果 可以根据结果自己做处理
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// 处理扫描结果（在界面上显示） 如果是url直接跳转
		if (requestCode==0x11 && resultCode == RESULT_OK) {
			Bundle bundle = data.getExtras();
			String scanResult = bundle.getString("result");
			if(scanResult.startsWith("http://")){
				scanQRCodeRes.setVisibility(View.GONE);
				Intent intent = new Intent();        
		        intent.setAction("android.intent.action.VIEW");    
		        Uri content_url = Uri.parse(scanResult);   
		        intent.setData(content_url);  
		        startActivity(intent);
			}else{
				scanQRCodeRes.setVisibility(View.VISIBLE);
				scanQRCodeRes.setText(scanResult);
			}
		}
	}

	private void showView(){
		
	}
	
}